package com.yellowpage.bigdata.action;

import java.io.IOException;
import java.util.*;

import com.yellowpage.tool.Excelexport;
import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.bigdata.data.TmApponoffImeiRetain;
import com.yellowpage.bigdata.service.TmApponoffImeiRetainService;

public class TmApponoffImeiRetainAction extends BaseAction {

	public String RESULT_QUERY = "query";
	public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";

	private Configuration configuration;

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	private List<TmApponoffImeiRetain> tmApponoffImeiRetainList = new ArrayList<TmApponoffImeiRetain>();
	private List<Map> resultList = new ArrayList<Map>();

	private TmApponoffImeiRetain tmApponoffImeiRetain;
	private TmApponoffImeiRetainService tmApponoffImeiRetainService;

	private String selectedId;
	private String[] selectedIds;
	private String message;

	private String query_tmApponoffImeiRetainId;
	private String query_logDate;

	private String query_startTime;
	private String query_endTime;
	private String query_note;
	private String query_imeiNewCount;
	private String query_nextDayRetained;
	private String query_sevenDayRetained;
	private String query_threeDayRetained;
	private String query_thirtyDayRetained;

	public void prepare() {
		super.prepare();

		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.tmApponoffImeiRetain = tmApponoffImeiRetainService
					.getTmApponoffImeiRetain(Long.parseLong(selectedId));
		}
	}

	public String queryByPage() {
		initPageRender();

		Map queryMap = new HashMap();

		queryMap.put("startTime", query_startTime);
		queryMap.put("endTime", query_endTime);
		queryMap.put("note", query_note);

		resultList = tmApponoffImeiRetainService
				.queryTmApponoffImeiRetainByPage(queryMap, pageRender);

		setPageRenderToRequest();

		return RESULT_QUERY;
	}

	// 给出excel导出策略
	public String exportExcel()

	{
		Map queryMap = new HashMap();

		queryMap.put("startTime", query_startTime);
		queryMap.put("endTime", query_endTime);
		queryMap.put("note", query_note);

		resultList = tmApponoffImeiRetainService
				.queryTmApponoffImeiRetainByPage(queryMap, null);

		LinkedHashMap<String, String> namemap = new LinkedHashMap<String, String>();

		// 给出中文名称
		namemap.put("SHOW_DATE", "日期");
		namemap.put("NEXT_RETAINED", "Imei新增数");
		namemap.put("THREE_RETAINED", "次日留存率");
		namemap.put("THREE_RETAINED", "第3日留存率");
		namemap.put("SEVEN_RETAINED", "第7日留存率");
		namemap.put("THIRTY_RETAINED", "第30日留存率");

		Excelexport.exportExcel(resultList, this.getClass().getName(), namemap);

		return null;

	}

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	public void setTmApponoffImeiRetain(
			TmApponoffImeiRetain tmApponoffImeiRetain) {
		this.tmApponoffImeiRetain = tmApponoffImeiRetain;
	}

	public TmApponoffImeiRetain getTmApponoffImeiRetain() {
		return tmApponoffImeiRetain;
	}

	public void setTmApponoffImeiRetainService(
			TmApponoffImeiRetainService tmApponoffImeiRetainService) {
		this.tmApponoffImeiRetainService = tmApponoffImeiRetainService;
	}

	public List<TmApponoffImeiRetain> getTmApponoffImeiRetainList() {
		return tmApponoffImeiRetainList;
	}

	public void setTmApponoffImeiRetainList(
			List<TmApponoffImeiRetain> tmApponoffImeiRetainList) {
		this.tmApponoffImeiRetainList = tmApponoffImeiRetainList;
	}

	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}

	public String getQuery_tmApponoffImeiRetainId() {
		return this.query_tmApponoffImeiRetainId;
	}

	public void setQuery_tmApponoffImeiRetainId(String tmApponoffImeiRetainId) {
		this.query_tmApponoffImeiRetainId = tmApponoffImeiRetainId;
	}

	public String getQuery_logDate() {
		return this.query_logDate;
	}

	public void setQuery_logDate(String logDate) {
		this.query_logDate = logDate;
	}

	public String getQuery_note() {
		return this.query_note;
	}

	public void setQuery_note(String note) {
		this.query_note = note;
	}

	public String getQuery_imeiNewCount() {
		return this.query_imeiNewCount;
	}

	public void setQuery_imeiNewCount(String imeiNewCount) {
		this.query_imeiNewCount = imeiNewCount;
	}

	public String getQuery_nextDayRetained() {
		return this.query_nextDayRetained;
	}

	public void setQuery_nextDayRetained(String nextDayRetained) {
		this.query_nextDayRetained = nextDayRetained;
	}

	public String getQuery_sevenDayRetained() {
		return this.query_sevenDayRetained;
	}

	public void setQuery_sevenDayRetained(String sevenDayRetained) {
		this.query_sevenDayRetained = sevenDayRetained;
	}

	public String getQuery_threeDayRetained() {
		return this.query_threeDayRetained;
	}

	public void setQuery_threeDayRetained(String threeDayRetained) {
		this.query_threeDayRetained = threeDayRetained;
	}

	public String getQuery_thirtyDayRetained() {
		return this.query_thirtyDayRetained;
	}

	public void setQuery_thirtyDayRetained(String thirtyDayRetained) {
		this.query_thirtyDayRetained = thirtyDayRetained;
	}

	public String getQuery_startTime() {
		return query_startTime;
	}

	public void setQuery_startTime(String query_startTime) {
		this.query_startTime = query_startTime;
	}

	public String getQuery_endTime() {
		return query_endTime;
	}

	public void setQuery_endTime(String query_endTime) {
		this.query_endTime = query_endTime;
	}

}
